home *** CD-ROM | disk | FTP | other *** search
- Path: news.cybercomm.net!usenet
- From: "J. Mark Hord" <pajtim@cybercomm.net>
- Newsgroups: comp.lang.c++
- Subject: Re: exit() and flushing data to ofstream files?
- Date: Tue, 26 Mar 1996 21:01:00 -0500
- Organization: CyberComm Online Services
- Message-ID: <3158A15C.58F7@cybercomm.net>
- References: <31584F18.29B2@apldbio.com>
- NNTP-Posting-Host: sl-010.sl.cybercomm.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- Nasser Abbasi wrote:
- >
- > hi,
- >
- > I am confused about something.
- >
- > according to "the C++ programming language", Bjarne Stroustrup
- > page 85 it says:
- > "..This can be done by calling exit(), which first clean things
- > like output streams."
- >
- > I take this as meaning that calling exit() from your C++
- > program will cause buffers to be flushed out to ofstream
- > files . well, this does no seem to be the case, this little
- > program shows that exit() do not flush data to file.
-
- I think it simply means that the destructor(s) will be called - the
- destructor may or may not flush but they do close the stream (or file).
-
- >
- > #include <fstream.h>
- > #include <stdlib.h>
- >
- > main()
- > {
- > ofstream f;
- >
- > f.open("tmp1");
- > f.put('X');
- > //f.flush();
- > exit(1); // this does not flush data to file
- > return 1;
- >
- > }
- >
- > Now looking at tmp I see no data in it.
- >
- > This is on Sun Solaris 2.5, using CC compiler.
- >
-
- Unfortunately, I do not have a copy of VC++ here at home or I would
- check to see how that handles it.
-
- > What is the recommended way to terminate the program
- > and have all buffers flushed automatically without having
- > to explicity call flush() on each open stream file ?
-
- Try the ios::unitbuf flag for flushing after each insertion and
- ios::stdio for flushing after each extraction.
-
- > Is this a bug or a feature of exit() ?
- >
- > thanks,
- > Nasser
- > Applied BioSystems
-